<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');?>
<?php
    
    class Report_model extends CI_Model{
        public function __construct(){
            parent::__construct();
            
            $prefix = 'invsys_';
            
            $this->tblCategory = $prefix.'Category';
            $this->tblSupplier = $prefix.'supplier';
            $this->tblProduct = $prefix.'product';
        }
        
        
        public function getsearchsupplier($key){
            $sql = "SELECT * FROM (`$this->tblSupplier`) WHERE ( `name` LIKE '%$key%' ) ORDER BY `idsupplier` desc";
            $data = $this->db->query($sql)->result_array();
            return $data;
        }

        public function getsearchproduct($key){
            $sql = "SELECT * FROM (`$this->tblProduct`) WHERE ( `name` LIKE '%$key%' ) ORDER BY `idproduct` desc";
            $data = $this->db->query($sql)->result_array();
            return $data;
        }
        
        
        
        public function getsummary($param){
            $datestart  = $param['datestart'];
            $dateend    = $param['dateend'];

            $sql = "SELECT `staff`.`codestaff`, `staff`.`firstname`, `staff`.`lastname`, `staff`.`mobile`, `staff`.`active`, `dep`.`name`, sum(`time`.`key`) as totaltime
                    FROM (`$this->tbltimesheet` as time) 
                    INNER JOIN $this->tblstaff as staff ON staff.idstaff=time.idstaff
                    INNER JOIN $this->tbldepartment as dep ON dep.iddepartment=staff.iddepartment
                    WHERE `datestart` >= '$datestart' AND `dateend` <= '$dateend' 
                    GROUP BY `time`.`idstaff`
                    ";
                    
            $data = $this->db->query($sql)->result_array();
            
            return $data;
        }
    }

?>



